package org.ruanjj.multithread.JUC;

public class HoldLockDemo {
    public static void main(String[] args) {
        HoldLockA h = new HoldLockA();
        new Thread(()->{
            h.AA();
        },"t1").start();

        new Thread(()->{
            h.BB();
        },"t2").start();
    }
}

class HoldLockA{
    public void AA(){
        synchronized (HoldLockA.class){
            System.out.println(Thread.currentThread().getName()+"AA");
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            BB();
        }
    }

    public synchronized void BB(){
        System.out.println(Thread.currentThread().getName()+"BB");
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        AA();
    }
}
